
/** variant.d: The unit test for dotmars/base/time.d

  Written in the D programming language 1.0

Authors:	Wei Li (oldrev@gmail.com)
Copyright:	Copyright (C) 2007 by Wei Li.
License:	BSD
*/

module test.base.testtime;

import dotmars.base.time;
import dotmars.test.core;

import dotmars.io.console;

class TimeSpanTestCase : TestCase!(TimeSpanTestCase)
{

	this()
	{
		register("testConverting", &testConverting);
		register("testOperators", &testOperators);
	}

	void testConverting() 
	{
		TimeSpan ts = TimeSpan(5, 4, 3, 2);
		assertTrue(ts.days == 5);
		assertTrue(ts.hours == 4);
		assertTrue(ts.minutes == 3);
		assertTrue(ts.seconds == 2);
		assertTrue(ts.totalDays > 5);
		assertTrue(ts.totalHours > 24 * 5 + 4);
	}

	void testOperators()
	{
		TimeSpan ts1 = TimeSpan(5, 4, 3, 2);
		TimeSpan ts2 = TimeSpan(1, 2, 3, 4);
		ts1 += ts2;
		assertTrue(ts1.days == 6);
		assertTrue(ts1.seconds == 6);
		assertTrue(ts1.minutes == 6);
		assertTrue(ts1.hours == 6);
	}
}

class DateTimeTestCase : TestCase!(DateTimeTestCase)
{
	this()
	{
		register("testProperties", &testProperties);
		register("testOperations", &testOperations);
	}

	void testProperties()
	{
		DateTime dt = DateTime(2007, 8, 26, 16, 36, 24);
		assertTrue(dt.month == 8);
		assertTrue(dt.hour == 16);
		assertTrue(dt.second == 24);
	}

	void testOperations()
	{
		DateTime dt = DateTime(2007, 8, 26, 16, 36, 24);
		dt = dt.addMonths(2);
		dt = dt.addSeconds(2);
		assertTrue(dt.month == 10);
		assertTrue(dt.second == 26);
		TimeSpan ts = TimeSpan(5, 4, 3, 2);
		dt -= ts;
		assertTrue(dt.day == 21);
		assertTrue(dt.minute == 33);
	}
}
